<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
    <!-- table -->
    <FormPanel ref="formPanel" :list="formList" :cols="1" :formType="'add'" labelWidth="130" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <div style="padding-top: 3rem;"></div>
      <div
      :style="{
        position: 'absolute',
        left: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    </Spin>
  </div>
</template>
<script>
import { editSave } from '@/api/claim/factory/SystemParameterMaintain';
export default {
  props: ['type', 'rowData'],
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      flterValue: {}, //参数
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList1(),
      saveData: null,
      activeName: '审核记录',
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.loading = true;
      this.formList.forEach((x) => {

        x.initialValue = this.rowData[x.fieldName];

        if (x.initialValue == 'XTCS00015') {
          this.formList.forEach((y) => {
            if (y.fieldName == 'para2') {
              y.disabled = false;
              y.hidden = false;
              y.rules[0].required = true;
            }
          });
        }
      });
      this.loading = false;
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    // //选中
    // selectChange(rows) {
    //   this.selectedRows = rows;
    //   console.log(this.selectedRows);
    // },
    //保存
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        console.log(this.saveData);
        //
        this.saveData.typeId = this.rowData.typeId;
        this.saveData.paraId = this.rowData.paraId;
        this.saveData.isDeleted = this.rowData.isDeleted;
        this.saveData.createdAt = this.rowData.createdAt;
        this.saveData.createdBy = this.rowData.createdBy;
        this.saveData.recordVersion = this.rowData.recordVersion;
        this.saveData.appId = this.rowData.appId;
        this.loading = true;
        let res = await editSave(this.saveData);
        this.loading = false;
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('addChange');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          // this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          // this.closeDialog();
        }
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    },
    add() {},
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '业务模块',
          fieldName: 'busModel',
          placeholder: '请输入业务模块...',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '参数代码',
          fieldName: 'paraCode',
          placeholder: '请输入参数代码...',
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '参数描述',
          fieldName: 'paraRemarks',
          placeholder: '请输入参数描述...',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '参数值1',
          fieldName: 'para1',
          placeholder: '请输入参数值...',
          rules: [{ required: true, message: '请输入参数值', trigger: 'blur' }],
          // rules: [{ pattern: /^(\d+)(\.?)(\d{0,9})$/, message: '请输入数字值', trigger: 'blur' }],
          // unitRender: () => {
          //   return <span>(元)</span>;
          // },
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '参数值2',
          fieldName: 'para2',
          placeholder: '请输入参数值...',
          disabled: true,
          hidden:true,
          rules: [{ required: false,pattern: /^(\d+)(\.?)(\d{0,9})$/, message: '请输入数字值', trigger: 'blur' }],
          // unitRender: () => {
          //   return <span>(元)</span>;
          // },
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        },
        // {
        //   type: 'INPUT',
        //   label: '参数值2',
        //   fieldName: 'para2',
        //   placeholder: '请输入参数值2...',
          // rules: [{ pattern: /^(\d+)(\.?)(\d{0,9})$/, message: '请输入数字值', trigger: 'blur' }],
          // unitRender: () => {
          //   return <span>(%)</span>;
          // },
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        // },
        // {
        //   type: 'INPUT',
        //   label: '或参数值3',
        //   fieldName: 'para3',
        //   placeholder: '请输入或参数值3...',
          // rules: [{ pattern: /^(\d+)(\.?)(\d{0,9})$/, message: '请输入数字值', trigger: 'blur' }],
          // unitRender: () => {
          //   return <span>(天)</span>;
          // },
          //  rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        // },
        // {
        //   type: 'INPUT',
        //   label: '或参数值4',
        //   fieldName: 'para4',
        //   placeholder: '或参数值4)...',
        //   // rules: [{ pattern: /^(\d+)(\.?)(\d{0,9})$/, message: '请输入数字值', trigger: 'blur' }],
        //   //  rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        // },
        // {
        //   type: 'DATE',
        //   label: '或*参数值(时间)',
        //   fieldName: 'para2',
        //   valueFormat: 'yyyy-MM-dd', //返回数据格式
        //   placeholder: '请输入或*参数值(时间)...',
        //   // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        // },
      ];
    },
  },
};
</script>

<style lang="less" scoped></style>
